package com.bdqn.ch05.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bdqn.ch05.pojo.SysUser;
import com.bdqn.ch05.repository.UserRepository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

@Service("sysUserService")
public class SysUserServiceImpl implements SysUserService{

    @Resource
    private UserRepository userRepository;

    @Override
    public SysUser login(String usrName, String usrPassword) {
        QueryWrapper<SysUser> wrapper = new QueryWrapper<SysUser>();
        wrapper.eq("usr_name", usrName);
        wrapper.eq("usr_password", usrPassword);
        return userRepository.selectOne(wrapper);
    }

    @Override
    public int addSysUser(SysUser sysUser) {
        return userRepository.insert(sysUser);
    }

    @Override
    public int deleteSysUser(Long usrId) {
        return userRepository.deleteById(usrId);
    }

    @Override
    public int updateSysUser(SysUser sysUser) {
        return userRepository.updateById(sysUser);
    }

    @Override
    public SysUser getSysUser(Long usrId) {
        return userRepository.selectById(usrId);
    }

    @Override
    public List<SysUser> findAllSysUsers() {
        return userRepository.selectList(null);
    }
}
